package com.yunfeisoft.business.service.impl;

import com.yunfeisoft.business.dao.inter.*;
import com.yunfeisoft.business.model.*;
import com.yunfeisoft.business.service.inter.ElderHealthService;
import com.yunfeisoft.common.base.BaseServiceImpl;
import com.yunfeisoft.common.sql.separation.DataSourceChange;
import com.yunfeisoft.common.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: ElderHealthServiceImpl
 * Description: 老人健康体检主表service实现
 * Author: Jackie liu
 * Date: 2020-04-04
 */
@Service("elderHealthService")
public class ElderHealthServiceImpl extends BaseServiceImpl<ElderHealth, String, ElderHealthDao> implements ElderHealthService {

    @Autowired
    private ElderLifeStyleDao elderLifeStyleDao;

    @Autowired
    private ElderHospitalizationDao elderHospitalizationDao;

    @Autowired
    private ElderHealthQuestionDao elderHealthQuestionDao;

    @Autowired
    private ElderOrganFunctionDao elderOrganFunctionDao;

    @Autowired
    private ElderPharmacyDao elderPharmacyDao;

    @Autowired
    private ElderHealthEvaluationDao elderHealthEvaluationDao;

    @Override
    @DataSourceChange(slave = true)
    public Page<ElderHealth> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    /**
     * 查询老人健康体检详细信息
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> queryAll(String id) {
        Map<String, Object> result = new HashMap<>();
        // 查询老人健康体检主表信息
        ElderHealth elderHealth = getDao().load(id);
        result.put("elderHealth", elderHealth);
        // 查询生活习惯从表
        ElderLifeStyle elderLifeStyle = elderLifeStyleDao.getByHealthId(id);
        result.put("elderLifeStyle", elderLifeStyle);
        // 查询住院情况从表
        List<ElderHospitalization> elderHospitalization = elderHospitalizationDao.getByHealthId(id);
        result.put("elderHospitalization", elderHospitalization);
        // 查询健康问题从表
        ElderHealthQuestion elderHealthQuestion = elderHealthQuestionDao.getByHealthId(id);
        result.put("elderHealthQuestion", elderHealthQuestion);
        // 查询脏器功能从表
        ElderOrganFunction elderOrganFunction = elderOrganFunctionDao.getByHealthId(id);
        result.put("elderOrganFunction", elderOrganFunction);
        // 主要用药情况
        List<ElderPharmacy> elderPharmacyList = elderPharmacyDao.getByHealthId(id);
        result.put("elderPharmacyList", elderPharmacyList);
        // 查询健康指导从表
        ElderHealthEvaluation elderHealthEvaluation = elderHealthEvaluationDao.getByHealthId(id);
        result.put("elderHealthEvaluation", elderHealthEvaluation);
        return result;
    }
}